package com.example.community.dao;

import com.example.community.mapper.PaytypeMapper;
import com.example.community.mapper.RepairMapper;
import com.example.community.mapper.UnitMapper;
import com.example.community.model.Paytype;
import com.example.community.model.Repair;
import com.example.community.model.Unit;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * 缴费类型表
 */
public class PaytypeDao {
    public Paytype fandById(Integer id){
        try (SqlSession session = MybatisUtil.getSession()){
            final PaytypeMapper mapper = session.getMapper(PaytypeMapper.class);
            return mapper.selectByPrimaryKey(id);
        }
    }

    public List<Paytype> fandByAll(){
        try (SqlSession session = MybatisUtil.getSession()){
            final PaytypeMapper mapper = session.getMapper(PaytypeMapper.class);
            return mapper.selectAll();
        }
    }

    public List<Paytype> fandLimit(Integer ys, Integer shuju){
        try (SqlSession session = MybatisUtil.getSession()){
            final PaytypeMapper mapper = session.getMapper(PaytypeMapper.class);
            Integer yss =(ys - 1) * shuju;
            return mapper.selectLimit(yss,shuju);
        }
    }

    public Integer selectLimitCount(Integer pageSize){
        try (SqlSession session = MybatisUtil.getSession()){
            final PaytypeMapper mapper = session.getMapper(PaytypeMapper.class);
            int count = mapper.CountPaytype();
            return (count + pageSize - 1)/pageSize;
        }
    }

    public Integer insert(Paytype paytype){
        try (SqlSession session = MybatisUtil.getSession()){
            final PaytypeMapper mapper = session.getMapper(PaytypeMapper.class);
            int i = mapper.insert(paytype);
            session.commit();
            return i;
        }
    }

    public Integer update(Paytype paytype){
        try (SqlSession session = MybatisUtil.getSession()){
            final PaytypeMapper mapper = session.getMapper(PaytypeMapper.class);
            int i = mapper.updateByPrimaryKey(paytype);
            session.commit();
            return i;
        }
    }

    public Integer delete(Integer id){
        try (SqlSession session = MybatisUtil.getSession()){
            final PaytypeMapper mapper = session.getMapper(PaytypeMapper.class);
            int i = mapper.deleteByPrimaryKey(id);
            session.commit();
            return i;
        }
    }
}
